package com.yami.shop.mystery.api.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.app.dto.*;
import com.yami.shop.bean.app.param.OrderItemParam;
import com.yami.shop.bean.app.param.SubmitMysteryBoxOrderParam;
import com.yami.shop.bean.enums.EsOperationType;
import com.yami.shop.bean.enums.OrderType;
import com.yami.shop.bean.enums.ProdStatusEnums;
import com.yami.shop.bean.enums.ShopStatus;
import com.yami.shop.bean.event.EsMysteryBoxUpdateEvent;
import com.yami.shop.bean.model.Order;
import com.yami.shop.bean.model.OrderItem;
import com.yami.shop.bean.model.ShopDetail;
import com.yami.shop.bean.model.ShopDivisionReceiver;
import com.yami.shop.bean.vo.EsMysteryBoxUpdateVO;
import com.yami.shop.bean.vo.EsProdUpdateVO;
import com.yami.shop.bean.vo.UserDeliveryInfoVO;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.Arith;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.config.ShopConfig;
import com.yami.shop.delivery.api.manager.DeliveryOrderManager;
import com.yami.shop.manager.SubmitOrderManager;
import com.yami.shop.manager.impl.ConfirmOrderManager;
import com.yami.shop.manager.impl.ShopCartAdapter;
import com.yami.shop.mystery.api.service.ActivityPresellManager;
import com.yami.shop.mystery.common.api.param.MysteryBoxOrderParam;
import com.yami.shop.mystery.common.dao.MysteryBoxSkuMapper;
import com.yami.shop.mystery.common.dto.ActivityPresellDto;
import com.yami.shop.mystery.common.dto.ActivityProdDto;
import com.yami.shop.mystery.common.dto.MysteryBoxOpenRecordDto;
import com.yami.shop.mystery.common.enums.ActivityRuleEnum;
import com.yami.shop.mystery.common.model.MysteryBox;
import com.yami.shop.mystery.common.model.MysteryBoxOpenRecord;
import com.yami.shop.mystery.common.model.MysteryBoxSku;
import com.yami.shop.mystery.common.service.ActivityPresellService;
import com.yami.shop.mystery.common.service.MysteryBoxOrderService;
import com.yami.shop.mystery.common.service.MysteryBoxService;
import com.yami.shop.security.api.model.YamiUser;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.OrderService;
import com.yami.shop.service.ShopCustomerService;
import com.yami.shop.service.ShopDetailService;
import com.yami.shop.service.ShopDivisionReceiverService;
import groovy.lang.Tuple;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 *
 * @author wxf
 * @date 2023/4/12 16:22
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/p/mysteryBox")
@Tag(name = "盲盒活动订单接口")
public class MysteryBoxOrderController {

    private final OrderService orderService;

    private final ActivityPresellService activityPresellService;

    private final ActivityPresellManager activityPresellManager;

    private final MysteryBoxService mysteryBoxService;

    private final MysteryBoxSkuMapper mysteryBoxSkuMapper;

    private final MysteryBoxOrderService mysteryBoxOrderService;

    private final SubmitOrderManager submitOrderManager;

    private final ConfirmOrderManager confirmOrderManager;

    private final ShopCartAdapter shopCartAdapter;

    private final DeliveryOrderManager deliveryOrderManager;

    private final ShopCustomerService shopCustomerService;

    private final ShopDetailService shopDetailService;

    private final ShopConfig shopConfig;

    private final ApplicationEventPublisher eventPublisher;

    private final ShopDivisionReceiverService shopDivisionReceiverService;

    @Operation(summary =  "确认订单")
    @PostMapping("/confirm")
    public ServerResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody MysteryBoxOrderParam orderParam) {
        String userId = SecurityUtils.getUser().getUserId();
        ActivityProdDto activityProdDto = checkActivityAndGetPresellPrice(orderParam, userId);
        List<ShopCartItemDto> shopCartItemsDb = getMysteryBoxShopCartItem(orderParam.getOrderItem(), activityProdDto.getPreemptionPrice());
        // 将要返回给前端的完整的订单信息
        ShopCartOrderMergerDto shopCartOrderMerger = new ShopCartOrderMergerDto();
        shopCartOrderMerger.setDvyType(orderParam.getDvyType());
        OrderType orderType = OrderType.ORDINARY;
        if (orderParam.getActivityId() > 0) {
            orderType = OrderType.PRESELL;
        }
        shopCartOrderMerger.setOrderType(orderType);
        shopCartOrderMerger.setActivityId(orderParam.getActivityId());

        // 筛选过滤掉不同配送的商品
        List<ShopCartItemDto> shopCartItems = confirmOrderManager.filterShopItemsByType(shopCartOrderMerger, shopCartItemsDb);
        // 该商品不满足任何的配送方式
        if (CollectionUtil.isEmpty(shopCartItems)) {
            return ServerResponseEntity.fail(ResponseEnum.ORDER_DELIVERY_NOT_SUPPORTED, shopCartOrderMerger);
        }

        ShopCartItemDto firstShopCartItem = shopCartItems.get(0);
        // 商品类别 0.实物商品 1. 虚拟商品 2.数字商品 3.盲盒商品
        int mold = 3;
        shopCartOrderMerger.setMold(mold);
        // 是否为预售订单
        orderParam.setPreSellStatus(firstShopCartItem.getPreSellStatus());
        shopCartOrderMerger.setPreSellStatus(firstShopCartItem.getPreSellStatus());

        // 购物车
        List<ShopCartDto> shopCarts = shopCartAdapter.getShopCarts(shopCartItems);

        // 计算运费，获取用户地址，自提信息
        UserDeliveryInfoVO userDeliveryInfo = new UserDeliveryInfoVO();
        if (Objects.equals(mold, 0)) {
            userDeliveryInfo = deliveryOrderManager.calculateAndGetDeliverInfo(userId, orderParam.getAddrId(), orderParam.getDvyType(), shopCartItems);
        }

        // 当算完一遍店铺的各种满减活动时，重算一遍订单金额
        confirmOrderManager.recalculateAmountWhenFinishingCalculateShop(shopCartOrderMerger, shopCarts, userDeliveryInfo);

        // 结束平台优惠的计算之后，还要重算一遍金额
        confirmOrderManager.recalculateAmountWhenFinishingCalculatePlatform(shopCartOrderMerger);

        // 计算平台佣金
        confirmOrderManager.calculatePlatformCommission(shopCartOrderMerger);

        // 缓存计算
        confirmOrderManager.cacheCalculatedInfo(userId, shopCartOrderMerger);
        return ServerResponseEntity.success(shopCartOrderMerger);
    }

    /**
     * 购物车/立即购买  提交订单,根据店铺拆单
     */
    @PostMapping("/submit")
    @Operation(summary =  "提交订单", description = "提交之后返回WebSocket路径，请求对应的WebSocket路径，开始等待响应")
    public ServerResponseEntity<Map> submitOrders(@Valid @RequestBody SubmitMysteryBoxOrderParam submitOrderParam) {
        String userId = SecurityUtils.getUser().getUserId();
        ServerResponseEntity<ShopCartOrderMergerDto> orderCheckResult = submitOrderManager.checkSubmitInfo(submitOrderParam, userId);
        if (!orderCheckResult.isSuccess()) {
            if(StrUtil.equals(ResponseEnum.REPEAT_ORDER.value(),orderCheckResult.getCode())){
                OrderNumbersDto orderNumbersDto = new OrderNumbersDto(null);
                orderNumbersDto.setDuplicateError(1);
                throw new YamiShopBindException("订单已过期，请重新下单");
            }
        }

        ShopCartOrderMergerDto mergerOrder = orderCheckResult.getData();
        //查询店铺新生信息
        ShopDetail shopDetailByShopId = shopDetailService.getShopDetailByShopId(mergerOrder.getShopCartOrders().get(0).getShopId());
        if(ObjectUtils.isEmpty(shopDetailByShopId.getShopXsUserId())){
            throw new YamiShopBindException("该店铺未绑定新生账号");
        }
        // 分账信息集合
        List<LedgerOrderDto> ledgerOrderDtos = new ArrayList<>();
        // 所有商品分账总计
        BigDecimal allDivide = new BigDecimal(BigInteger.ZERO);
        List<ShopCartOrderDto> shopCartOrders = mergerOrder.getShopCartOrders();
        for (ShopCartOrderDto shopCartOrder : shopCartOrders) {
            List<ShopCartItemDiscountDto> shopCartItemDiscounts = shopCartOrder.getShopCartItemDiscounts();
            for (ShopCartItemDiscountDto shopCartItemDiscount : shopCartItemDiscounts) {
                List<ShopCartItemDto> shopCartItems = shopCartItemDiscount.getShopCartItems();
                for (ShopCartItemDto shopCartItem : shopCartItems) {
                    Long prodId = shopCartItem.getProdId();
                    MysteryBox mysteryBox = mysteryBoxService.detail(prodId);
                    if (mysteryBox.getStatus() != ProdStatusEnums.NORMAL.getValue() && mysteryBox.getStatus() != ProdStatusEnums.PRESELL.getValue()) {
                        throw new YamiShopBindException("盲盒商品:["+mysteryBox.getProdName()+"]已下架");
                    }
                    // 计算每个商品的分账信息
                    if(ObjectUtil.isNotNull(shopCartItem.getReceiverGroupId())){
                        List<ShopDivisionReceiver> receivers = shopDivisionReceiverService.list(
                                new LambdaQueryWrapper<ShopDivisionReceiver>()
                                        .eq(ShopDivisionReceiver::getReceiverGroupId, shopCartItem.getReceiverGroupId())
                                        .eq(ShopDivisionReceiver::getShopId, shopDetailByShopId.getShopId())
                                        .eq(ShopDivisionReceiver::getState, 1));
                        for (ShopDivisionReceiver receiver : receivers) {
                            LedgerOrderDto divideAcct = new LedgerOrderDto();
                            divideAcct.setLedgerUserId(receiver.getAccNo());
                            BigDecimal divide = new BigDecimal(String.valueOf(mergerOrder.getTotal())).multiply(receiver.getDivisionProfit()).setScale(2, RoundingMode.HALF_DOWN);
                            divideAcct.setAmount(divide.toString());
                            ledgerOrderDtos.add(divideAcct);
                            allDivide = allDivide.add(divide);
                        }
                    }
                }
            }
        }

        List<Order> orders = mysteryBoxOrderService.submit(mergerOrder);
        StringBuilder orderNumbers = new StringBuilder();
        Set<Long> prodIds = new HashSet<>();
        for (Order order : orders) {
            orderNumbers.append(order.getOrderNumber()).append(StrUtil.COMMA);
            prodIds.addAll(order.getOrderItems().stream().map(OrderItem::getProdId).collect(Collectors.toSet()));
        }
        orderNumbers.deleteCharAt(orderNumbers.length() - 1);

        // 店铺客户创建
        shopCustomerService.saveCustomerByOrders(orders);

        // 更新es中的商品库存
//        eventPublisher.publishEvent(new EsMysteryBoxUpdateEvent(null, new ArrayList<>(prodIds), EsOperationType.UPDATE_BATCH));
        orderService.removeConfirmOrderCache(userId + submitOrderParam.getUuid());

        // 更新es中的商品库存--更新失败打印日志，优先保证订单流程没问题
        try {
            List<EsProdUpdateVO> prodUpdateVOS = mergerOrder.getProdList();
            List<EsMysteryBoxUpdateVO> mysteryBoxUpdateVOS = new ArrayList<>();
            prodUpdateVOS.forEach(a ->{
                EsMysteryBoxUpdateVO vo = new EsMysteryBoxUpdateVO();
                vo.setBoxId(a.getProdId());
                vo.setCount(a.getCount());
                vo.setType(a.getType());
                mysteryBoxUpdateVOS.add(vo);
            });
            eventPublisher.publishEvent(new EsMysteryBoxUpdateEvent(mysteryBoxUpdateVOS, EsOperationType.UPDATE_ORDER_STOCK_NUM_BATCH));
        } catch (Exception e) {
            log.error("提交订单-更新es盲盒商品库存失败，错误为：{}", e);
        }
        // 平台佣金分账信息

        LedgerOrderDto merchantToPlatform = new LedgerOrderDto();
        merchantToPlatform.setLedgerUserId(shopConfig.getHnaPay().getMerId());
        merchantToPlatform.setAmount(mergerOrder.getShopCartOrders().get(0).getPlatformCommission().toString());
        ledgerOrderDtos.add(merchantToPlatform);
        // 计算店铺剩余分账金额
        LedgerOrderDto merchantToShop  = new LedgerOrderDto();
        merchantToShop.setLedgerUserId(shopDetailByShopId.getShopXsUserId());
        //店铺分账金额
        BigDecimal shopAmount = new BigDecimal(String.valueOf(mergerOrder.getTotal())).subtract(new BigDecimal(String.valueOf(mergerOrder.getShopCartOrders().get(0).getPlatformCommission())));
        merchantToShop.setAmount(String.valueOf(shopAmount));
        ledgerOrderDtos.add(merchantToShop);
        Map<Object,Object> orderMap = new HashMap<Object,Object>();
        orderMap.put("ledgerOrderDtos", JSONUtil.toJsonStr(ledgerOrderDtos));
        orderMap.put("orderNumbers",orderNumbers);

        return ServerResponseEntity.success(orderMap);

    }

    /**
     * 检查活动状态
     */
    private ActivityProdDto checkActivityAndGetPresellPrice(MysteryBoxOrderParam orderParam, String userId) {

        if (orderParam.getActivityId() == 0) {
            ActivityProdDto prodDto = new ActivityProdDto();
            prodDto.setPreemptionPrice(0);
            return prodDto;
        }

        Long prodId = orderParam.getOrderItem().getProdId();
        ActivityPresellDto activityDto = activityPresellService.detail(orderParam.getActivityId());
        if (Objects.isNull(activityDto) || !Objects.equals(activityDto.getStatus(), 0)
                || activityDto.getActivityEndTime().getTime() < System.currentTimeMillis()
                || activityDto.getActivityStartTime().getTime() > System.currentTimeMillis()) {
            // 预售活动不在进行中，请稍后重试
            throw new YamiShopBindException("盲盒活动不在进行中，请稍后重试");
        }

        ActivityProdDto prodDto = null;
        List<ActivityProdDto> prods = activityDto.getProds();
        for (ActivityProdDto dto : prods) {
            if (Objects.equals(dto.getProdId(), prodId)) {
                prodDto = dto;
                break;
            }
        }
        if (Objects.isNull(prodDto)) {
            // 活动商品不在正常状态
            throw new YamiShopBindException("yami.group.prod.status.error");
        }

        activityDto.setSpuId(prodId);
        Tuple tuple = activityPresellManager.checkUser(activityDto, userId);
        if (!(boolean) tuple.get(0)) {
            // 活动商品不在正常状态
            throw new YamiShopBindException("用户无法购买");
        }

        Long maxNum = (Long) tuple.get(1);
        if (!(boolean) tuple.get(4)) {
            // 预售活动不在进行中，请稍后重试
            throw new YamiShopBindException("用户无法购买");
        }
        String ruleType = (String)tuple.get(5);
        if (ActivityRuleEnum.DISCOUNTS.getValue().equals(ruleType)) {
            BigDecimal pric = new BigDecimal(activityDto.getPreemptionPrice() + "").divide(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP);
            prodDto.setPreemptionPrice(pric.doubleValue());
        }
        /**
         * 限购数 不等于0 是限购
         */
        if(maxNum != 0) {
            // 大于限购数量
            if (orderParam.getOrderItem().getProdCount() > maxNum.intValue()) {
                log.info("orderConfirm-{} 您购买数量超出限购数量",userId);
                throw new YamiShopBindException("您购买数量超出限购数量");
            }
            /*
            // 当前业务需求不校验已购买数，只关注当前订单购买数量
            // 小于限购数量
            Integer orderPurchaseCount = 0;
            // 获取当前时间所处时间段，如果是优惠购时间段，查优惠购购买数，如果是优先购时间段，查优先购购买数，大众购买时间段，查大众购买购买数
            Date date = new Date();
            if (activityDto.getIsDiscounts() == 1 && activityDto.getDiscountsStartTime().getTime() <= date.getTime()
                    && activityDto.getDiscountsEndTime().getTime() >= date.getTime()) {
                orderPurchaseCount = mysteryBoxOrderMapper.selectNumByUser(prodId, orderParam.getActivityId(), userId, activityDto.getDiscountsStartTime(), activityDto.getDiscountsEndTime());
            } else if (activityDto.getIsPreemption()== 1 && activityDto.getPreemptionStartTime().getTime() <= date.getTime()
                    && activityDto.getPreemptionEndTime().getTime() >= date.getTime()) {
                orderPurchaseCount = mysteryBoxOrderMapper.selectNumByUser(prodId, orderParam.getActivityId(), userId, activityDto.getPreemptionStartTime(), activityDto.getPreemptionEndTime());
            } else if (activityDto.getPutawayTime().getTime() <= date.getTime()) {
                orderPurchaseCount = mysteryBoxOrderMapper.selectNumByUser(prodId, orderParam.getActivityId(), userId, activityDto.getPutawayTime(), null);
            }
            if (orderPurchaseCount <= maxNum.intValue()) {
                // 剩余限购数量
                Integer counts = maxNum.intValue() - orderPurchaseCount;
                if (orderParam.getOrderItem().getProdCount() > counts) {
                    log.info("orderConfirm-{} 您购买数量超出限购数量!",userId);
                    throw new YamiShopBindException("您购买数量超出限购数量");
                }
            }*/
        }

        return prodDto;
    }

    /**
     * 将参数转换成组装好的购物项
     * @param orderItem 购物车物品参数
     * @param activityPriceFee 活动价
     * @return 商品购物项
     */
    private List<ShopCartItemDto> getMysteryBoxShopCartItem(OrderItemParam orderItem, Double activityPriceFee) {
        MysteryBoxSku mysteryBoxSku = mysteryBoxSkuMapper.getByMysteryBoxId(orderItem.getProdId());
        if (Objects.isNull(mysteryBoxSku)) {
            // 订单包含无法识别的商品
            throw new RuntimeException("yami.order.unrecognized.prod");
        }
        MysteryBox mysteryBox = mysteryBoxService.getById(orderItem.getProdId());
        if (Objects.isNull(mysteryBox)) {
            // 订单包含无法识别的商品
            throw new RuntimeException("yami.order.unrecognized.prod");
        }
        if (orderItem.getProdCount() < 1) {
            // 下单商品数量不能小于1
            throw new RuntimeException("yami.order.prod.count.limit");
        }
        // 拿到购物车的所有item
        ShopCartItemDto shopCartItem = new ShopCartItemDto();
        shopCartItem.setBasketId(-1L);
        shopCartItem.setSkuId(mysteryBoxSku.getId());
        shopCartItem.setProdId(mysteryBox.getId());
        shopCartItem.setProdType(4); // 盲盒
        shopCartItem.setProdCount(orderItem.getProdCount());
        shopCartItem.setCategoryId(mysteryBox.getCategoryId());

        shopCartItem.setMold(2);
        shopCartItem.setSkuName(mysteryBox.getBoxName());
        shopCartItem.setProdName(mysteryBox.getBoxName());
        shopCartItem.setPic(mysteryBox.getPic());
        shopCartItem.setBasketDate(new Date());
        shopCartItem.setDistributionCardNo(orderItem.getDistributionCardNo());
        shopCartItem.setPrice(mysteryBox.getPrice());
        shopCartItem.setProductTotalAmount(Arith.mul(mysteryBox.getPrice(), orderItem.getProdCount()));
        // 初始化商品实际金额
        shopCartItem.setActualTotal(shopCartItem.getProductTotalAmount());
        shopCartItem.setShareReduce(0.0);
        // 如果有活动价并且活动价大于0则使用活动价格
        if (activityPriceFee != null && activityPriceFee > 0.0) {
            // 商品实际金额，优惠金额放入店铺金额
            shopCartItem.setPrice(activityPriceFee);
            shopCartItem.setActualTotal(Arith.mul(shopCartItem.getProdCount(), activityPriceFee));
            double shareReduce = Math.max(Arith.sub(shopCartItem.getProductTotalAmount(), shopCartItem.getActualTotal()), 0.0);
            shopCartItem.setShareReduce(shareReduce);
            // 如果活动价大于商品价格，则设置下原价
            shopCartItem.setProductTotalAmount(Arith.mul(shopCartItem.getPrice(), orderItem.getProdCount()));
        }

        if (mysteryBox.getShopId() == 0) {
            shopCartItem.setShopId(Constant.PLATFORM_SHOP_ID);
            shopCartItem.setShopName(Constant.PLATFORM_SHOP_NAME);
        } else {
            ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(mysteryBox.getShopId());
            if (!Objects.equals(shopDetail.getShopStatus(), ShopStatus.OPEN.value())) {
                // 店铺不处于营业状态
                throw new YamiShopBindException("yami.store.shop.state.check");
            }
            shopCartItem.setShopId(shopDetail.getShopId());
            shopCartItem.setShopName(shopDetail.getShopName());
        }
        shopCartItem.setIsDelivery(true);
        List<ShopCartItemDto> shopCartItems = new ArrayList<>();
        shopCartItems.add(shopCartItem);
        return shopCartItems;
    }

    @Operation(summary =  "持有盲盒个数", description = "持有盲盒个数")
    @GetMapping("/getMyBoxNum")
    public ServerResponseEntity<Long> getMyBoxNum(String channelCode) {
        YamiUser shopUser = SecurityUtils.getUser();
        return ServerResponseEntity.success(mysteryBoxService.getMyBoxNum(shopUser.getUserId(), channelCode));
    }

    @Operation(summary =  "持有盲盒列表", description = "持有盲盒列表")
    @GetMapping("/getMyBoxPage")
    public ServerResponseEntity<IPage<MysteryBox>> getMyBoxPage(PageParam<MysteryBox> page, MysteryBox param) {
        YamiUser shopUser = SecurityUtils.getUser();
        return ServerResponseEntity.success(mysteryBoxService.getMyBoxPage(page, shopUser.getUserId(), param));
    }

    @Operation(summary =  "持有盲盒详情", description = "持有盲盒详情")
    @GetMapping("/myBoxDetail")
    public ServerResponseEntity<MysteryBox> myBoxDetail(Long boxId) {
        YamiUser shopUser = SecurityUtils.getUser();
        return ServerResponseEntity.success(mysteryBoxService.myBoxDetail(shopUser.getUserId(), boxId));
    }

    @Operation(summary =  "盲盒详情列表", description = "盲盒详情列表")
    @GetMapping("/getBoxrecords")
    public ServerResponseEntity<IPage<MysteryBoxOpenRecordDto>> getBoxrecords(PageParam<MysteryBoxOpenRecord> page, Long boxId){
        YamiUser user = SecurityUtils.getUser();
        return ServerResponseEntity.success(mysteryBoxService.getBoxrecords(page, user.getUserId(), boxId));
    }

    @Operation(summary =  "开盲盒", description = "开盲盒")
    @GetMapping("/openMyBox")
    public ServerResponseEntity openMyBox(@RequestParam("boxId") Long boxId, @RequestParam("openNum") Integer openNum) {
        YamiUser shopUser = SecurityUtils.getUser();
        return ServerResponseEntity.success(mysteryBoxService.openMyBox(shopUser.getUserId(), boxId, openNum));
    }

    @Operation(summary =  "已开盲盒列表", description = "已开盲盒列表")
    @GetMapping("/getMyOpenBoxPage")
    public ServerResponseEntity<IPage<MysteryBoxOpenRecord>> getMyOpenBoxPage(PageParam<MysteryBoxOpenRecord> page, MysteryBoxOpenRecord param) {
        YamiUser shopUser = SecurityUtils.getUser();
        return ServerResponseEntity.success(mysteryBoxService.getMyOpenBoxPage(page, shopUser.getUserId(), param));
    }
}
